package com.ruoyi.web.controller.common;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.lark.oapi.Client;
import com.lark.oapi.core.Config;
import com.lark.oapi.core.utils.Jsons;
import com.lark.oapi.service.approval.v4.model.GetInstanceReq;
import com.lark.oapi.service.approval.v4.model.GetInstanceResp;
import com.lark.oapi.service.contact.v3.model.*;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.ruoyi.GetToken;
import com.ruoyi.baseMain.domain.bo.*;
import com.ruoyi.baseMain.domain.vo.BaseAccountVo;
import com.ruoyi.baseMain.domain.vo.BasePolicyHisVo;
import com.ruoyi.baseMain.service.IBaseCustomService;
import com.ruoyi.baseMain.service.IBasePolicyHisService;
import com.ruoyi.baseMain.service.IBasePolicyService;
import com.ruoyi.baseMain.service.impl.BaseAccountServiceImpl;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.ocean.domain.bo.OceanLogTotalBo;
import com.ruoyi.ocean.domain.vo.OceanLogTotalVo;
import com.ruoyi.ocean.mapper.OceanLogTotalMapper;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.controller.api.Department;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.List;
import java.util.Objects;

/**
 * @author linziheng
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/feishu")
public class OpenFeishuController {


    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private final IBasePolicyService iBasePolicyService;
    @Autowired
    private final IBasePolicyHisService iBasePolicyHisService;
    @Autowired
    private final IBaseCustomService iBaseCustomService;
    @Autowired
    private ISysDeptService iSysDeptService;
    @Autowired
    private BaseAccountServiceImpl baseAccountServiceImpl;

    @Autowired
    private ISysUserService iSysUserService;
    @Autowired
    private final OceanLogTotalMapper baseMapper;


    @PostMapping("/getCustomList")
    public R getCustomList(String token) {
        System.out.println(token);
        List<BaseCustomFeishuDto> list = iBaseCustomService.queryListToFeishu();
        JSONObject map = new JSONObject();
        map.put("options",list);
        JSONObject texts = new JSONObject();
        list.forEach( item ->{
            texts.put(item.getValue(),item.getValue());
        });
        JSONArray i18nResources = new JSONArray();
        JSONObject zh_cn = new JSONObject();
        zh_cn.put("locale","zh_cn");
        zh_cn.put("isDefault",true);
        zh_cn.put("texts",texts);

        i18nResources.add(zh_cn);

        map.put("i18nResources",i18nResources);
        map.put("hasMore",false);
        JSONObject map2 = new JSONObject();
        map2.put("result",map);
        return R.ok2(map2);
    }



    @PostMapping("/getMedium")
    public R getMedium(String token) {
        System.out.println(token);
        List<BaseCustomFeishuDto> list = iBaseCustomService.getMedium();
        JSONObject map = new JSONObject();
        map.put("options",list);
        JSONObject texts = new JSONObject();
        list.forEach( item ->{
            texts.put(item.getValue(),item.getValue());
        });
        JSONArray i18nResources = new JSONArray();
        JSONObject zh_cn = new JSONObject();
        zh_cn.put("locale","zh_cn");
        zh_cn.put("isDefault",true);
        zh_cn.put("texts",texts);

        i18nResources.add(zh_cn);

        map.put("i18nResources",i18nResources);
        map.put("hasMore",false);
        JSONObject map2 = new JSONObject();
        map2.put("result",map);
        return R.ok2(map2);
    }

}
